import { createApp } from 'vue'
import elementPlus from 'element-plus'
import App from './App.vue'
import router from './router'

// import './mock/mock_serve'
import { ElMessage } from 'element-plus'

import 'element-plus/lib/theme-chalk/index.css'
import 'element-plus/lib/theme-chalk/display.css'

router.beforeEach((to,form,next)=>{
    let pathArr = to.path.split('/')
    // console.log(arr)
    console.log(pathArr[1])
    let user = JSON.parse(window.sessionStorage.getItem('info')) || null
    //投票页，登录页，注册页可以不用登陆访问
    if ( !user && (to.path == '/register')){
        next()
    }else if ( !user && (pathArr[1] == 'VoteDetail')){
        next()
    }else if ( !user && to.path != '/login'){
        ElMessage.error('请先登录');
        next('/login')
    }else{
        next()
    }
})
createApp(App).use(router).use(elementPlus).mount('#app')

